package com.xiubai.appforpda;

import android.app.Application;
import android.content.Context;

import com.uuzuche.lib_zxing.activity.ZXingLibrary;
import com.xiubai.appforpda.db.DatabaseUtils;
import com.xiubai.appforpda.jack.lib.net.GlobalRequestFilter;
import com.xiubai.appforpda.jack.lib.net.RequestInformation;
import com.xiubai.appforpda.jack.utils.Constants;
import com.xiubai.appforpda.jack.utils.SharedPreferenceTool;

import java.util.HashMap;

/**
 * @author: r3562939
 * @version: V1.0
 * @project: AppForPda
 * @description: description
 * @date: 2018/11/13
 * @time: 13:05
 */
public class App extends Application {
    public static Context mContext;
    public static boolean ALREADY_SYNC = false;

    @Override
    public void onCreate() {
        super.onCreate();
        mContext = this;
        initGlobalConfig();
        DatabaseUtils.initHelper(this, "app_for_pda.db");
        ZXingLibrary.initDisplayOpinion(this);
    }

    // 初始化cookie
    private void initGlobalConfig() {
        RequestInformation.mGlobalRequestFilter = new GlobalRequestFilter() {

            @Override public HashMap<String, String> filterHeader() {
                String mCookie =
                        SharedPreferenceTool.getInstance().getString(SharedPreferenceTool.COOKIE_KEY, "");
                if (mCookie != null) {
                    HashMap<String, String> header = new HashMap<String, String>();
                    header.put(Constants.KEY_COOKIE_INFO, mCookie);
                    return header;
                }
                return null;
            }
        };
    }
}
